//
//  YGGoodsTableViewCell.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/16.
//

#import "YGGoodsTableViewCell.h"

@interface YGGoodsTableViewCell ()

@property (nonatomic, strong) UIButton *selectBtn;
@property (nonatomic, strong) UIImageView *goodsImageView;
@property (nonatomic, strong) UILabel *goodsNameLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UIButton *reduceBtn;
@property (nonatomic, strong) UIButton *changeAmountBtn;
@property (nonatomic, strong) UIButton *addBtn;




@end

@implementation YGGoodsTableViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initconstraints];
    }
    return self;
}

-(void)initView{
    [self addSubview:self.selectBtn];
    [self addSubview:self.goodsImageView];
    [self addSubview:self.goodsNameLabel];
    [self addSubview:self.priceLabel];
    [self addSubview:self.reduceBtn];
    [self addSubview:self.changeAmountBtn];
    [self addSubview:self.addBtn];
}

-(void)initconstraints{
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
            make.left.mas_equalTo(self.contentView.mas_left).offset(10);
            make.width.mas_equalTo(12);
            make.height.mas_equalTo(12);
    }];
    
    [self.goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.contentView.mas_centerY);
            make.left.mas_equalTo(self.selectBtn.mas_right).offset(20);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(100);
    }];
    
    [self.goodsNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.contentView.mas_top).offset(25);
            make.left.mas_equalTo(self.goodsImageView.mas_right).offset(25);
            make.width.mas_equalTo(154);
            make.height.mas_equalTo(30);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-25);
            make.left.mas_equalTo(self.goodsImageView.mas_right).offset(25);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(10);
    }];
    
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-25);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(22);
    }];
    
    [self.changeAmountBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.addBtn.mas_bottom);
            make.right.mas_equalTo(self.addBtn.mas_left).offset(0.001);
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(22);
    }];
    
    [self.reduceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.changeAmountBtn.mas_bottom);
            make.right.mas_equalTo(self.changeAmountBtn.mas_left).offset(0.001);
            make.width.mas_equalTo(20);
            make.height.mas_equalTo(22);
    }];
    
}

#pragma -event
-(void)clickReduceAmountAction{
    
}

-(void)clickChangeAmountAction{
    
}

-(void)clickAddAmountAction{
    
}

#pragma setter
- (UIButton *)selectBtn{
    if (!_selectBtn) {
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectBtn setBackgroundImage:[UIImage imageNamed:@"gender_btn_icon"] forState:UIControlStateNormal];
        [_selectBtn setBackgroundImage:[UIImage imageNamed:@"gender_selected_btn_icon"] forState:UIControlStateSelected];
        _selectBtn.selected = NO;
    }
    return _selectBtn;
}

- (UIImageView *)goodsImageView{
    if (!_goodsImageView) {
        _goodsImageView = [[UIImageView alloc]init];
        _goodsImageView.backgroundColor = [UIColor whiteColor];
    }
    return _goodsImageView;
}

- (UILabel *)goodsNameLabel{
    if (!_goodsNameLabel) {
        _goodsNameLabel = [[UILabel alloc]init];
        _goodsNameLabel.font = [UIFont systemFontOfSize:12];
        _goodsNameLabel.textColor = UIColorFromRGB(0x333333);
    }
    return _goodsNameLabel;
}

- (UILabel *)priceLabel{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc]init];
        _priceLabel.text = @"￥";
        _priceLabel.font = [UIFont systemFontOfSize:12];
        _priceLabel.textColor = UIColorFromRGB(0xE55667);
    }
    return _priceLabel;
}

- (UIButton *)reduceBtn{
    if (!_reduceBtn) {
        _reduceBtn = [[UIButton alloc]init];
        [_reduceBtn addTarget:self action:@selector(clickReduceAmountAction) forControlEvents:UIControlEventTouchUpInside];
        [_reduceBtn setTitle:@"-" forState:UIControlStateNormal];
        [_reduceBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        _reduceBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _reduceBtn;
}

- (UIButton *)changeAmountBtn{
    if (!_changeAmountBtn) {
        _changeAmountBtn = [[UIButton alloc]init];
        [_changeAmountBtn addTarget:self action:@selector(clickChangeAmountAction) forControlEvents:UIControlEventTouchUpInside];
        [_changeAmountBtn setTitle:@"1" forState:UIControlStateNormal];
        [_changeAmountBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        _changeAmountBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _changeAmountBtn;
}

- (UIButton *)addBtn{
    if (!_addBtn) {
        _addBtn = [[UIButton alloc]init];
        [_addBtn addTarget:self action:@selector(clickAddAmountAction) forControlEvents:UIControlEventTouchUpInside];
        [_addBtn setTitle:@"+" forState:UIControlStateNormal];
        [_addBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        _addBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        
    }
    return _addBtn;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
